﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KenLib.BusinessManager;
using KenLib.BusinessObject;
using DataInfo;

public partial class JOINT_frmJ_TestResultInput : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ((JOINT_MstPage_JOINT)this.Master).changeTitle("テスト結果一括登録");
        ((JOINT_MstPage_JOINT)this.Master).HideLiArea("frmJ_TestResultInput");
        if (Session["役"] == null || Session["役"].ToString() == "")
        {
            Response.Redirect("~/frmD_Login.aspx");
        }
        if (!Page.IsPostBack)
        {
          
            面接日.Focus();
            bind面接日();
            bind応募者();
            Page.Header.Title = "テスト結果一括登録"; ;
        }
        Page.Header.Title = "テスト結果一括登録";
        RequiredFieldValidator応募者.ErrorMessage = GetError("ER00007"); 
        RequiredFieldValidator点数.ErrorMessage = GetError("ER00001"); ;
        RequiredFieldValidator回答率.ErrorMessage = GetError("ER00001"); 
        RequiredFieldValidator性格診断結果.ErrorMessage = GetError("ER00001"); 
        CustomValidator点数.ErrorMessage = GetError("ER00002"); 
        CustomValidator回答率.ErrorMessage = GetError("ER00002"); 
    }
    public void bind面接日()
    {
        try
        {
            面接情報Manager frm = new 面接情報Manager();
            DataTable dt = frm.sp_frmJ_TestResultInput_dll面接日();
            DataColumn objDataColumn = new DataColumn("data", Type.GetType("System.String"));
            dt.Columns.Add(objDataColumn);
            foreach (DataRow row in dt.Rows)
            {
                string result = row["YYYY/MM/DD"] + " " + row["企業名"];
                row["data"] = result;
            }
            ddl_面接日.DataSource = dt;
            ddl_面接日.DataTextField = "data";
            ddl_面接日.DataValueField = "ID";
            ddl_面接日.DataBind();
            ListItem item = new ListItem("[選択]", "-1");
            item.Selected = true;
            ddl_面接日.Items.Insert(0, item);
        }
        catch { }
    }
    public void bind応募者()
    {
        try
        {
            応募情報Manager frm = new 応募情報Manager();
            DataTable dt = frm.sp_frmJ_TestResultInput_dll応募者All(Convert.ToInt32(ddl_面接日.SelectedValue));
            ddl応募者.DataSource = dt;
            ddl応募者.DataTextField = "氏名";
            ddl応募者.DataValueField = "応募情報ID";
            ddl応募者.DataBind();
            ListItem item = new ListItem("[選択]", "-1");
            item.Selected = true;
            ddl応募者.Items.Insert(0, item);
        }
        catch (Exception ex)
        {

        }
    }
    protected void ddl_面接日_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (ddl_面接日.SelectedValue.ToString() != "-1")
        {
            int 面接日ID = Convert.ToInt32(ddl_面接日.SelectedValue.ToString());
            応募情報Manager manager = new 応募情報Manager();
            DataTable table = manager.sp_frmJ_TestResultInput_dll応募者(面接日ID);
            ddl応募者.DataSource = table;
            ddl応募者.DataTextField = "氏名";
            ddl応募者.DataValueField = "応募情報ID";
            ddl応募者.DataBind();
            ListItem item = new ListItem("[選択]", "-1");
            item.Selected = true;
            ddl応募者.Items.Insert(0, item);
            ddl_面接日.Focus();
            txt点数.Text = "";
            txt回答率.Text = "";
            txt性格診断結果.Text = "";
        }
        else
        {
            bind応募者();
        }
    }
    protected void btn完了_Click(object sender, EventArgs e)
    {
        応募情報 obj = new 応募情報();
        try
        {
            if (ddl応募者.SelectedValue.ToString() != "-1")
            {
                int ID = Convert.ToInt32(ddl応募者.SelectedValue.ToString());
                obj.ID = ID;
            }
            obj.数学テスト結果点数1 = Convert.ToInt32(txt点数.Text.ToString());
            obj.数学テスト結果回答率 = Convert.ToInt32(txt回答率.Text.ToString());
            obj.性格診断結果 = HttpUtility.HtmlEncode(txt性格診断結果.Text.ToString());
            応募情報Manager manager = new 応募情報Manager();
            manager.sp_frmJ_TestResultInput_Update(obj);
            Response.Redirect("frmJ_TestResultInput.aspx");
        }
        catch (Exception ex) {
        }

    }
    protected void btnキャンセル_Click(object sender, EventArgs e)
    {
        Response.Redirect("frmJ_TraineeManager.aspx");
    }
    protected void ddl応募者_SelectedIndexChanged(object sender, EventArgs e)
    {
        応募情報Manager manager = new 応募情報Manager();
        if (ddl応募者.SelectedValue.ToString() != "-1")
        {
            int ID = Convert.ToInt32(ddl応募者.SelectedValue.ToString());
            DataTable dt = manager.sp_frmJ_TestResultInput_Load(ID);
            txt点数.Text = dt.Rows[0]["数学テスト結果点数"].ToString();
            txt回答率.Text = dt.Rows[0]["数学テスト結果回答率"].ToString();
            txt性格診断結果.Text = dt.Rows[0]["性格診断結果"].ToString();
            ddl応募者.Focus();
        }

    }
    public String GetError(string errorid)//ham lay message loi duoi db
    {
        string error = "";
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        if (dt.Rows.Count > 0)
        {
            return error = dt.Rows[0][2].ToString();
        }
        else
        {
            return error;
        }
    }
}


